#include "ShortListNotificationMenu.h"
#include "StringUtilities.h"
#include "Utilities.h"
#include "PrintUtilities.h"
#include "MenuManager.h"
#include "ServiceProvider.h"
#include "UserSelectionMenu.h"
#include "User.h"
#include "People.h"
#include "UserManager.h"
#include "Team.h"

ShortListNotificationMenu::ShortListNotificationMenu(MenuManager* const i_menuManager)
	:Menu(i_menuManager)
	,m_player(0)
	,m_user(0)
{
}

ShortListNotificationMenu::~ShortListNotificationMenu(void)
{
}

void ShortListNotificationMenu::OnEnter()
{
	if(m_user == 0)
	{
		UserSelectionMenu* usMenu = static_cast<UserSelectionMenu*>(GetMM()->GetUserSelectionMenu());
		m_user = GetSP()->GetUserMgr().GetUserList().at( usMenu->GetUserSelected());
	}

	m_add = !Utilities::IsPresent(m_user->m_shortlist, m_player->GetId());
}

void ShortListNotificationMenu::OnExit()
{
	m_user = 0;
	m_player = 0;
}

void ShortListNotificationMenu::Draw() const
{
	using STD::cout;
	using STD::endl;

	cout << Print::Title("SHORTLIST NOTIFICATION MENU:") << endl;

	cout << "Team " << m_user->m_team->GetName() << (m_add ? " ADDS " : " REMOVES ")
		<< m_player->GetName() << " from his shortlist" << endl << endl;

	cout << Print::Options("0) Return to previous menu'.");
	cout << "Selection: ";	
}

bool ShortListNotificationMenu::Input(const STL::string& i_input)
{
	size_t res = Utilities::StringToInt(i_input);

	if(res != 0)
		return false;

	if(m_add)
		m_user->m_shortlist.push_back(m_player->GetId());
	else
		Utilities::erase_unordered(m_user->m_shortlist, m_player->GetId());

	GetMM()->PopMenu();

	return true;
}

